<template>
  <TableLayout :permissions="['system:user:query']">
    <!-- 搜索表单 -->
    <el-form ref="searchForm" slot="search-form" :model="searchForm" label-width="80px" inline>
<#list table.queryFields as field>
      <el-form-item label="${field.comment}" prop="${field.camelCaseName}">
        <el-input v-model="searchForm.${field.camelCaseName}" v-trim placeholder="请输入${field.comment}" @keypress.enter.native="search"/>
      </el-form-item>
</#list>
      <section>
        <el-button type="primary" icon="el-icon-search" @click="search">搜索</el-button>
        <el-button @click="reset">重置</el-button>
      </section>
    </el-form>
    <!-- 表格和分页 -->
    <template v-slot:table-wrap>
      <ul class="toolbar"<#if withPerm=='true'> v-permissions="['${moduleName}:${table.camelCaseName}:create', '${moduleName}:${table.camelCaseName}:delete']"</#if>>
        <li<#if withPerm=='true'> v-permissions="['${moduleName}:${table.camelCaseName}:create']"</#if>><el-button type="primary" @click="$refs.opera${table.pascalCaseName}Window.open(`新建${table.comment}`)" icon="el-icon-plus">新建</el-button></li>
        <li<#if withPerm=='true'> v-permissions="['${moduleName}:${table.camelCaseName}:delete']"</#if>><el-button @click="deleteByIdInBatch" icon="el-icon-delete">删除</el-button></li>
      </ul>
      <el-table
          v-loading="isWorking.search"
          :data="tableData.list"
          stripe
          @selection-change="handleSelectionChange"
          @sort-change="handleSortChange"
      >
        <el-table-column type="selection" fixed="left" width="55"></el-table-column>
<#list table.tableFields as field>
        <el-table-column prop="${field.camelCaseName}" label="${field.comment}" min-width="100px"<#if field.fixDirection!='none'> fixed="${field.fixDirection}"</#if>></el-table-column>
</#list>
        <el-table-column
        <#if withPerm=='true'>
          v-if="containPermissions(['${moduleName}:${table.camelCaseName}:update', '${moduleName}:${table.camelCaseName}:delete'])"
        </#if>
          label="操作"
          min-width="270"
          fixed="right"
        >
          <template slot-scope="{ row }">
            <el-button<#if withPerm=='true'> v-permissions="['${moduleName}:${table.camelCaseName}:update']"</#if> type="text" @click="$refs.opera${table.pascalCaseName}Window.open(`编辑${table.comment}`, row)" icon="el-icon-edit">编辑</el-button>
            <el-button<#if withPerm=='true'> v-permissions="['${moduleName}:${table.camelCaseName}:delete']"</#if> type="text" @click="deleteById(row)" icon="el-icon-delete">删除</el-button>
          </template>
        </el-table-column>
      </el-table>
      <pagination
          @size-change="handleSizeChange"
          @current-change="handlePageChange"
          :pagination="tableData.pagination"
      ></pagination>
    </template>
    <!-- 新建/修改 -->
    <Opera${table.pascalCaseName}Window ref="opera${table.pascalCaseName}Window" @success="handlePageChange(tableData.pagination.pageIndex)"/>
  </TableLayout>
</template>

<script>
import Pagination from '@/components/common/Pagination'
import TableLayout from '@/layouts/TableLayout'
import BaseTable from '@/components/base/BaseTable'
import Opera${table.pascalCaseName}Window from '@/components/${moduleName}/Opera${table.pascalCaseName}Window'
export default {
  extends: BaseTable,
  components: { Opera${table.pascalCaseName}Window, TableLayout, Pagination },
  data () {
    return {
      // 搜索
      searchForm: {
<#list table.queryFields as field>
        ${field.camelCaseName}: ''<#if field_index<table.queryFields?size-1>,</#if>
</#list>
      }
    }
  },
  created () {
    this.config({
      module: '${table.comment}',
      api: '/${moduleName}/${table.kebabCaseName}',
      sorts: []
    })
    this.search()
  }
}
</script>

<style scoped lang="scss">
</style>
